package com.aube.control.player;

import android.content.Context;
import android.media.AudioManager;
import android.view.Surface;

import com.aube.multiscreen.AbsPlayCallback;
import com.huyn.baseframework.model.VideoPlayModel;

/**
 * Created by huyn on 2015/9/23.
 * 主镜头是纯vr的视频处理逻辑
 */
public class MajorVRTextureVideoHelper extends MajorTextureVideoHelper {

    public MajorVRTextureVideoHelper(Context context, VideoPlayModel video, ISurfaceTextureProvider provider, AbsPlayCallback playCallback) {
        this(context, video, true, provider, playCallback);
    }

    public MajorVRTextureVideoHelper(Context context, VideoPlayModel video, boolean enableVolume, ISurfaceTextureProvider provider, AbsPlayCallback playCallback) {
        this.enableVolume = enableVolume;
        this.mContext = context;
        this.iProvider = provider;
        setPlayCallback(playCallback);
        initPlayInfo(context, video);
    }

    protected void initPlayInfo(Context context, VideoPlayModel video) {
        super.initPlayInfo(context, video);

        if(!DO_NOT_USE_CC)
            texturePrepared(getSurface());
    }

    @Override
    protected void texturePrepared(Surface surface) {
        myListener = createMyListener();

        if(surface != null)
            player.setSurface(surface);

        if (mRunningOnBackground.get()) {
            mRunningOnBackground.set(false);
        }

        isDestroyed.set(false);

        manageSound(enableVolume);

        player.setAudioStreamType(AudioManager.STREAM_MUSIC);
        player.setOnBufferingUpdateListener(myListener);
        player.setOnPreparedListener(myListener);
        player.setOnSeekCompleteListener(myListener);
        player.setOnCompletionListener(myListener);
    }

}
